<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/9/11
 * Time: 13:37
 */
namespace app\franchisee\controller;
use think\Db;
use think\Request;
class Echarts extends Base {
    public function __construct()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }
    }
    public function index(){
        extract(input());
        $type = input('param.type');
        $start = input('param.start');
        $end = input('param.end');
        //总订单
        if($type==1){
            $where['order_fb_ym'] = $start;
        }elseif ($type==2){
            $where['order_fb_ym'] = array('between',array($start,$end));
        }
        $where['order_status'] = array('>',7);
        $where['order_jms_user'] = $user_id;
        $res = Db::table('up_order')->where($where)->count();
        $total_num = Db::table('up_order')->where($where)->sum('order_freight');
        // 未结算未逾期
        $map['order_status'] = array('>',7);
        if($type==1){
            $map['order_fb_ym'] = $start;
        }elseif ($type==2){
            $map['order_fb_ym'] = array('between',array($start,$end));
        }
        $map['jiesuan'] = 1;
        $map['con_type'] = 1;
        $map['order_contract_date'] = array('>=',date('Y-m-d'));
        $map['order_jms_user'] = $user_id;
        $res1 = Db::table('up_order')->where($map)->count();
        $total_num1 = Db::table('up_order')->where($map)->sum('order_freight');
        //未结算已逾期
        $map1['order_status'] = array('>',7);
        if($type==1){
            $map1['order_fb_ym'] = $start;
        }elseif ($type==2){
            $map1['order_fb_ym'] = array('between',array($start,$end));
        }
        $map1['jiesuan'] = 1;
        $map1['con_type'] = 1;
        $map1['order_contract_date'] = array('<',date('Y-m-d'));
        $map1['order_jms_user'] = $user_id;
        $res2 = Db::table('up_order')->where($map1)->count();
        $total_num2 = Db::table('up_order')->where($map1)->sum('order_freight');
        $list['res'] = $res;
        $list['total_num'] = $total_num;
        $list['res1'] = $res1;
        $list['total_num1'] = $total_num1;
        $list['res2'] = $res2;
        $list['total_num2'] = $total_num2;
        return json(['status' => 200, 'msg' => $list]);
    }

    public function index1(){
        extract(input());
        $type = input('param.type');
        $start = input('param.start');
        $end = input('param.end');
        if($type==1){
            $where['order_fb_ym'] = $start;
        }elseif ($type==2){
            $where['order_fb_ym'] = array('between',array($start,$end));
        }
        $where['order_status'] = array('>',7);
        $where['order_jms_user'] = $user_id;
        //获取总金额
        $total_num = Db::table('up_order')->where($where)->sum('order_freight');
        //税赋
        $price1 = round(($total_num/1.09)*0.09,2) ;
        //保险成本
        $price2 = round($total_num*0.06,2);
        //平台抽成
        if($total_num<30000){
            $price3 = round($total_num*0.0358,2);
        }elseif ($total_num>=30000&&$total_num<300000){
            $price3 = round($total_num*0.0258,2);
        }elseif ($total_num>=300000){
            $price3 = round($total_num*0.0198,2);
        }
        $total_num1 = Db::table('up_order')->where($where)->sum('order_dzxy_freight');
        $list['price1'] = $price1;
        $list['price2'] = $price2;
        $list['price3'] = $price3;
        $list['price4'] = $total_num1;
        return json(['status' => 200, 'msg' => $list]);
    }

    public function index2(){
        extract(input());
        $type = input('param.type');
        $start = input('param.start');
        $end = input('param.end');
        if($type==1){
            $where['order_fb_ym'] = $start;
        }elseif ($type==2){
            $where['order_fb_ym'] = array('between',array($start,$end));
        }
        $where['order_status'] = array('>',7);
        $where['order_jms_user'] = $user_id;
        //获取总金额
        $total_num = Db::table('up_order')->where($where)->sum('order_freight');
        //税赋
        $price1 = round(($total_num/1.09)*0.09,2) ;
        //保险成本
        $price2 = round($total_num*0.06,2);
        //平台抽成
        if($total_num<30000){
            $price3 = round($total_num*0.0358,2);
        }elseif ($total_num>=30000&&$total_num<300000){
            $price3 = round($total_num*0.0258,2);
        }elseif ($total_num>=300000){
            $price3 = round($total_num*0.0198,2);
        }
        //司机成本
        $total_num1 = Db::table('up_order')->where($where)->sum('order_dzxy_freight');
        //支出
        $total = $price1+$price2+$price3+$total_num1;
        $jing_total = $total_num - $total;
        $list['total_num'] = $total_num;
        $list['total'] = $total;
        $list['jing_total'] = $jing_total;
        return json(['status' => 200, 'msg' => $list]);
    }

    public function index3(){
        extract(input());
        $type = input('param.type');
        $start = input('param.start');
        $end = input('param.end');
        if($type==1){
            $where['oder_detail_ym'] = $start;
        }elseif ($type==2){
            $where['oder_detail_ym'] = array('between',array($start,$end));
        }
        $res1 = Db::table('up_order_detail')
            ->where($where)
            ->where('user_id',$user_id)
            ->where('order_detail_type',1)
            ->select();
        $res2 = Db::table('up_order_detail')
            ->where($where)
            ->where('user_id',$user_id)
            ->where('order_detail_type',2)
            ->select();
        $list['res1'] = $res1;
        $list['res2'] = $res2;
        return json(['status' => 200, 'msg' => $list]);
    }

    public function detail(){
        extract(input());
        $id = input('param.order_id');
        $where['a.order_id'] = $id;
        $res = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
            ->join('up_u_user uuu','uuu.user_id = a.order_jms_user')
            ->join('up_car_zxlx ucz' ,'ucz.zxlx_id = a.zxlx_id','left')
            ->where($where)
            ->field('a.*,ua.district as go_sheng,ua1.district as go_shi,
                        ua2.district as to_sheng,ua3.district as to_shi,
                        uuu.user_phone,uuu.user_real_name,uuu.user_username
                        ,ucz.zxlx_name,uch.hwlx_name')
            ->find();
        $total_num = $res['order_freight'];
        //税赋
        $price1 = round(($total_num/1.09)*0.09,2) ;
        //保险成本
        $price2 = round($total_num*0.06,2);
        //平台抽成
        if($total_num<30000){
            $price3 = round($total_num*0.0358,2);
        }elseif ($total_num>=30000&&$total_num<300000){
            $price3 = round($total_num*0.0258,2);
        }elseif ($total_num>=300000){
            $price3 = round($total_num*0.0198,2);
        }
        //司机成本
        $total_num1 = $res['order_dzxy_freight'];
        //支出
        $total = $price1+$price2+$price3+$total_num1;
        $res['price1'] = $price1;
        $res['price3'] = $price3;
        $res['price2'] = $price2;
        $res['total_num1'] = $total_num1;
        $res['total1'] =$total_num-$total;
        return json(['status' => 200, 'msg' => $res]);
    }


}